<?php 
class Administrator{
   
   /**
    * Array permission
   */
   public $arr_pms = array();
   
   /**
    * 
    * The id, username and password
   */
   public $id,$username,$password,$type;
   
   /**
    * 
    * The constructor
   */
   public function __construct($u,$p){
      
      $this->username = $u;
      $this->password = $p;
      $this->check_login();
   }
   public function check_login(){
      $sql = "SELECT 
                  *
				 FROM 
                  administrator
				 WHERE 
                  adt_username = :username 
             AND 
                  adt_password = :password
             AND 
                  adt_status = 1";
      $db = new DB();
      $check = $db->row($sql,array('username'=> $this->username,
                                 'password' => md5($this->password)));
                                 
      if(is_array($check) && !empty($check)){
         $_SESSION['ad_type']       = $check['adt_type'];
    		$_SESSION["logged"]			= 1;
    		$_SESSION["user_id"]		   = $check['adt_id'];
    		$_SESSION["userlogin"]		= $check['adt_username'];
   		$this->id    = $check['adt_id'];
         $this->type  = $check['adt_type'];
   		return $this->id;
   	}
   	else{
 	       session_destroy();
   		return 0;
   	}
   }
   
   public function getPermission(){
      if($this->type == 1){
         $string_query = "SELECT  
                              mod_name,
                              mod_file,
                              mod_dir,
                              mod_sub 
                           FROM 
                              modules 
                           WHERE 
                              mod_active = 1 
                           ORDER BY 
                              mod_order";
      }else{
         $string_query = "SELECT 
                              mod_name,
                              mod_file,
                              mod_dir,
                              mod_sub  
                           FROM 
                              modules
                           INNER JOIN  
                              author
                           ON
                              modules.mod_id = author.mod_id
                           WHERE 
                              mod_active = 1
                              AND
                              adt_id = ".$this->id." 
                           ORDER BY 
                              mod_order";
         $db = new DB();
         $this->arr_pms = $db->query($string_query);
         unset($db_query);
      }
   }
   
   
   
}
?>